package cn.kgc.controller;    /*
 *@author wangchangsheng
 *@Date 2023/4/27
 */

import cn.kgc.bean.pojo.EpUser;
import cn.kgc.bean.vo.LoginRequest;
import cn.kgc.bean.vo.Result;
import cn.kgc.bean.vo.ResultCodeEnum;
import cn.kgc.common.TokenUtils;
import cn.kgc.service.EpUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;


@RestController
@RequestMapping("/epUser")
@Slf4j
public class EpUserController {

    @Resource
    private EpUserService epUserService;

    @PostMapping("/getLogin")
    public  Result getLogin(@RequestBody LoginRequest loginRequest){
        String loginName = loginRequest.getLoginName();
        String password =loginRequest.getPassword();
        EpUser epUser = epUserService.getLogin(loginName,password);
        if (epUser!=null){
            EpUser token = epUser;
            return Result.success(token);
        }else {
            return  Result.failure(ResultCodeEnum.PARAM_AUTH_USER_NOT_EXIST);
        }
    }



    @PostMapping("/register")
    public Result addEpUser(@RequestBody EpUser epUser){
        String LoginName = epUser.getLoginName();
        epUser.setUsername(LoginName);
        boolean flsg=epUserService.addEpUser(epUser);
        if (flsg){
            return Result.success(flsg);
        }else {
            return Result.failure();
        }
    }
}

